// 本文件由自动工具 proto.py 自动生成，请勿修改
// filename test1_csbuf.lua
// package test


test = test or {}

-- message Head
test.Head = {
	protoid = 1000,
	a: number = 0;
	b: string = "";
}

function test.Head:Marshal(writer)
	writer:setUint32(this.a, 1)
	writer:setString(this.b, 2)
end

function test.Head:Unmarshal(reader)
	this.a = reader:getUint32(1)
	this.b = reader:getString(2)
end

function test.Head:create()
	return clone(test.Head)
end

-- message Test1
test.Test1 = {
	protoid = 2001,
	a_t1: number = 0;
	at_2: number = 0;
	at3_: string = "";
	t4: number = [],
	t5: string = [],
	t6 = test.Head:create(),
	t7: Head = [],
}

function test.Test1:Marshal(writer)
	writer:setUint8(this.a_t1, 1)
	writer:setUint32(this.at_2, 2)
	writer:setString(this.at3_, 3)
	writer:setArray(#this.t4, 4)
	for (let v of this.t4) {
		writer:setUint32(v, 0)
	}
	writer:setArray(#this.t5, 5)
	for (let v of this.t5) {
		writer:setString(v, 0)
	}
	writer:setMessage(6)
	self.t6:Marshal(writer)
	writer:endSetMessage()
	writer:setArray(#this.t7, 7)
	for (let v of this.t7) {
		writer:setMessage(0)
	v:Marshal(writer)
	writer:endSetMessage()
	}
end

function test.Test1:Unmarshal(reader)
	this.a_t1 = reader:getUint8(1)
	this.at_2 = reader:getUint32(2)
	this.at3_ = reader:getString(3)
	local count = reader:getArray(4)
	for (let i=1; i < count; i++) {
		this.t4.push(reader:getUint32(0)))
	}
	local count = reader:getArray(5)
	for (let i=1; i < count; i++) {
		this.t5.push(reader:getString(0)))
	}
	reader:getMessage(6)
	self.t6:Unmarshal(reader)
	reader:endGetMessage()
	local count = reader:getArray(7)
	for (let i=1; i < count; i++) {
		local msg = test.Head:create()
		reader:getMessage(0)
	msg:Unmarshal(reader)
	reader:endGetMessage()
		this.t7.push( msg)
	}
end

function test.Test1:create()
	return clone(test.Test1)
end

-- message Test2
test.Test2 = {
	protoid = 2002,
	a_t1: number = 0;
	at_2: number = 0;
	at3_: string = "";
	t6 = test.Head:create(),
	t7: Head = [],
}

function test.Test2:Marshal(writer)
	writer:setUint8(this.a_t1, 1)
	writer:setUint32(this.at_2, 2)
	writer:setString(this.at3_, 3)
	writer:setMessage(6)
	self.t6:Marshal(writer)
	writer:endSetMessage()
	writer:setArray(#this.t7, 7)
	for (let v of this.t7) {
		writer:setMessage(0)
	v:Marshal(writer)
	writer:endSetMessage()
	}
end

function test.Test2:Unmarshal(reader)
	this.a_t1 = reader:getUint8(1)
	this.at_2 = reader:getUint32(2)
	this.at3_ = reader:getString(3)
	reader:getMessage(6)
	self.t6:Unmarshal(reader)
	reader:endGetMessage()
	local count = reader:getArray(7)
	for (let i=1; i < count; i++) {
		local msg = test.Head:create()
		reader:getMessage(0)
	msg:Unmarshal(reader)
	reader:endGetMessage()
		this.t7.push( msg)
	}
end

function test.Test2:create()
	return clone(test.Test2)
end

return test
